﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;
namespace DAL
{
    public class TLDAL
    {
        DBHelper db = new DBHelper();
        public List<TLModel> GetListAll()
        {
            string sql = $"select * from [dbo].[TeacherAdjust]";
            List<TLModel> list = new List<TLModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TLModel DM = new TLModel();
                DM.ID = Convert.ToInt32(dt.Rows[i]["ID"].ToString());
                DM.TeacherName = dt.Rows[i]["TeacherName"].ToString();
                DM.TeacherEvent = dt.Rows[i]["TeacherEvent"].ToString();
                DM.LeaveTime = dt.Rows[i]["LeaveTime"].ToString();
                DM.LeaveApprove = Convert.ToInt32(dt.Rows[i]["LeaveApprove"].ToString());
                list.Add(DM);
            }
            return list;
        }
        public bool Add(TLModel DM)
        {
            string sql = $"insert into [dbo].[TeacherAdjust] values('{DM.TeacherName}','{DM.TeacherEvent}','{DM.LeaveTime}','')";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool Update(TLModel DM)
        {
            string sql = $"update [dbo].[TeacherAdjust] set [LeaveApprove] ='{DM.LeaveApprove}' where [ID] ='{DM.ID}'";
            if (db.SetData(sql))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public List<TLModel> GetListAlll()
        {
            string sql = $"select * from [dbo].[Duty]";
            List<TLModel> list = new List<TLModel>();
            DataTable dt = db.GetData(sql).Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TLModel DM = new TLModel();
                DM.DutyID = Convert.ToInt32(dt.Rows[i]["DutyID"].ToString());
                DM.DutyDay = dt.Rows[i]["DutyDay"].ToString();
                DM.DutyNo = dt.Rows[i]["DutyNo"].ToString();
                list.Add(DM);
            }
            return list;
        }
    }
}
